package com.yonglian.management.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import jakarta.validation.constraints.*;
import java.io.Serializable;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Set;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * A Activity.
 */
@Entity
@Table(name = "activity")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class Activity implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @NotNull
    @Size(min = 2, max = 50)
    @Column(name = "activity_name", length = 50, nullable = false)
    private String activityName;

    @Column(name = "create_time")
    private ZonedDateTime createTime;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "activity")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnoreProperties(value = { "activity" }, allowSetters = true)
    private Set<ActivityProperty> properties = new HashSet<>();

    @ManyToOne(fetch = FetchType.EAGER)
    @JsonIgnoreProperties(value = { "activities", "projectType" }, allowSetters = true)
    private ProjectBaseInfo project;

    // jhipster-needle-entity-add-field - JHipster will add fields here

    public Long getId() {
        return this.id;
    }

    public Activity id(Long id) {
        this.setId(id);
        return this;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getActivityName() {
        return this.activityName;
    }

    public Activity activityName(String activityName) {
        this.setActivityName(activityName);
        return this;
    }

    public void setActivityName(String activityName) {
        this.activityName = activityName;
    }

    public ZonedDateTime getCreateTime() {
        return this.createTime;
    }

    public Activity createTime(ZonedDateTime createTime) {
        this.setCreateTime(createTime);
        return this;
    }

    public void setCreateTime(ZonedDateTime createTime) {
        this.createTime = createTime;
    }

    public Set<ActivityProperty> getProperties() {
        return this.properties;
    }

    public void setProperties(Set<ActivityProperty> activityProperties) {
        if (this.properties != null) {
            this.properties.forEach(i -> i.setActivity(null));
        }
        if (activityProperties != null) {
            activityProperties.forEach(i -> i.setActivity(this));
        }
        this.properties = activityProperties;
    }

    public Activity properties(Set<ActivityProperty> activityProperties) {
        this.setProperties(activityProperties);
        return this;
    }

    public Activity addProperty(ActivityProperty activityProperty) {
        this.properties.add(activityProperty);
        activityProperty.setActivity(this);
        return this;
    }

    public Activity removeProperty(ActivityProperty activityProperty) {
        this.properties.remove(activityProperty);
        activityProperty.setActivity(null);
        return this;
    }

    public ProjectBaseInfo getProject() {
        return this.project;
    }

    public void setProject(ProjectBaseInfo projectBaseInfo) {
        this.project = projectBaseInfo;
    }

    public Activity project(ProjectBaseInfo projectBaseInfo) {
        this.setProject(projectBaseInfo);
        return this;
    }

    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Activity)) {
            return false;
        }
        return getId() != null && getId().equals(((Activity) o).getId());
    }

    @Override
    public int hashCode() {
        // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
        return getClass().hashCode();
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "Activity{" +
            "id=" + getId() +
            ", activityName='" + getActivityName() + "'" +
            ", createTime='" + getCreateTime() + "'" +
            "}";
    }
}
